﻿using Windows.Storage;

namespace FASTControlUI
{
    public struct GameConfigData
    {
        public OutpurReportPedal ReportPedal;
        public OutputReportWheel ReportWheel;
    }
    public static class GameDataPublic
    {
        public static ApplicationDataContainer LocalSetting { get { return ApplicationData.Current.LocalSettings; } }
        public static OutpurReportPedal ReportPedal;
        public static OutputReportWheel ReportWheel;
        public static int WheelForce { get; set; }

        public static void Save()
        {
            ConfigManager<GameConfigData> configManager = new ConfigManager<GameConfigData>(ConfigManager<GameConfigData>.MainConfig);
            GameConfigData configData = new GameConfigData();
            configData.ReportPedal = ReportPedal;
            configData.ReportWheel = ReportWheel;
            configManager["GameConfig"] = configData;
            //Type info = typeof(GameDataPublic);
            //PropertyInfo[] propertys = info.GetProperties(BindingFlags.Public | BindingFlags.Static);
            //foreach (PropertyInfo pi in propertys)
            //{
            //    //获取属性名称
            //    if (pi.Name == "LocalSetting")
            //        continue;
            //    string name = pi.PropertyType.Name;
            //    string propertyName = pi.Name;
            //    LocalSetting.Values[propertyName] = pi.GetValue(info);
            //}
        }

        public static void Load()
        {
            ConfigManager<GameConfigData> configManager = new ConfigManager<GameConfigData>(ConfigManager<GameConfigData>.MainConfig);
            GameConfigData configData = configManager["GameConfig"];
            ReportPedal = configData.ReportPedal;
            ReportWheel = configData.ReportWheel;
            //Type info = typeof(GameDataPublic);
            //PropertyInfo[] propertys = info.GetProperties(BindingFlags.Public | BindingFlags.Static);
            //foreach (PropertyInfo pi in propertys)
            //{
            //    //获取属性名称
            //    if (pi.PropertyType.Name != "Int32")
            //        continue;
            //    string propertyName = pi.Name;
            //    if (LocalSetting.Values[propertyName] is int value)
            //    {
            //        pi.SetValue(info, value);
            //    }
            //}
        }
    }
}
